<template>
  <div class="register">
    <van-nav-bar title="注册" left-arrow @click-left="onClickLeft" />
    <div class="input-box">
      <div class="number">
        手机号：+86
        <input type="text" v-model="account" />
      </div>
      <div class="password">
        设置密码：
        <input type="password" v-model="password" />
      </div>
      <div class="affirm">
        确认密码：
        <input type="password" v-model="word" />
      </div>
      <button class="zhuce" @click="study">注册</button>
    </div>
  </div>
</template>

<script>
import { post } from "../../tools/request";
export default {
  data() {
    return {
      account: "",
      password: "",
      word: "",
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push({
        name: "user",
      });
    },
    study() {
      if (this.password === this.word) {
        post("/api/l1/newUser", {
          account: this.account,
          password: this.password,
        }).then((res) => {
          if (res.tit === "注册成功") {
            this.$router.push({
              name: "Number",
            });
            console.log(res);
          } else {
            alert("请输入11位手机号");
          }
        });
      } else {
        alert("密码不一致");
      }
    },
  },
  created() {
    this.$store.commit("tabHide");
  },
};
</script>

<style lang="scss">
.register {
  .van-nav-bar__title {
    font-weight: bold;
    font-size: 16px;
    line-height: 150%;
    text-align: center;
    font-weight: bold;
  }
  .input-box {
    width: 291px;
    height: 273px;
    margin: 80px auto;
    position: relative;
    .number,
    .password,
    .affirm {
      height: 50px;
      border-bottom: 1px solid rgba(236, 238, 241, 1);
      color: rgba(120, 130, 153, 1);
      font-size: 14px;
      line-height: 50px;
      input {
        border: 0;
        line-height: 30px;
        // color: #f2f4f8;
        font-size: 12px;
      }
    }
    .zhuce {
      height: 37px;
      width: 100%;
      text-align: center;
      line-height: 37px;
      border: 0;
      background-color: rgba(51, 177, 123, 1);
      color: white;
      position: absolute;
      bottom: 0;
      border-radius: 4px;
    }
  }
}
</style>